<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link rel="stylesheet" href="${initParam.root }/css/board/main_boardWriteUpdate.css">
<script src="${initParam.root}/jquery-1.8.3.js"></script>
<script type="text/javascript">
var xhr;
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xhr = new XMLHttpRequest();
	}
}
function startRequest(newfilename) {
	createXMLHttpRequest();
	xhr.onreadystatechange = callback;
	xhr.open("post", "board.do", true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	xhr.send("command=deleteFile&newfilename=${requestScope.bvo.newfilename}");
}
function callback() {
	if (xhr.readyState == 4) {
		if (xhr.status == 200) {
			//var jsonData=JSON.parse(xhr.responseText);
			document.getElementById("uploadView").innerHTML 
			= "<input type='file' name='uploadFile'>";
		}
	}
}
$(function(){
	$("#gogoUpdate").click(function(){
		var flag=confirm("수정하시겠습니까?");
		if(flag){
			$("#updateContentForm").submit();
		}
	});//click
	$("#cancel").click(function(){
		var flag=confirm("수정을 취소하시겠습니까?");
		if(flag)
			location.href="board.do?command=findAllQnaforPaging";
	});//click
});//ready

</script>
<div id="전체틀">
	<header id="title">
		<font>수정페이지</font>
	</header>
	<div id="update">
		<form action="board.do" method="post" name="upadte_form" enctype="multipart/form-data" id="updateContentForm">
		<input type="hidden" name="command" value="qnaUpdate">
		<input type="hidden" name="b_no" value="${requestScope.bvo.b_no }">
		<input type="hidden" name="b_writer" value="${requestScope.bvo.b_writer }">
		<input type="hidden" name="b_cnt" value="${requestScope.bvo.b_cnt }">
		<input type="hidden" name="m_id" value="${requestScope.bvo.m_id }">
			<table>
				<tr>
					<td>제목</td><td><input type="text" name="b_title" maxlength="100" size="30" value="${requestScope.bvo.b_title }"></td>
				</tr>
				<tr>
					<td colspan="2">
						<span id="uploadView">
							<c:choose>
								<c:when test="${requestScope.bvo.orgfilename!=null }" >
				     			${requestScope.bvo.orgfilename}<a href="javascript:startRequest()">삭제</a>
								</c:when>
								<c:otherwise>
									<input type="file" name="uploadFile">
								</c:otherwise>
							</c:choose>
						</span>
					</td>
				</tr>
				<tr>
					<td colspan="2"><textarea cols="35" rows="10" name="b_content">${requestScope.bvo.b_content }</textarea></td>
				</tr> 
				<tr>
					<td colspan="2"  ><img src="${initParam.root }/img/paging/confirm.gif" id="gogoUpdate"><img src="${initParam.root }/img/paging/cancel.gif" id="cancel"></td>  
				</tr>
			</table>
		</form>
	</div>
</div> 
